package conf

import (
	gcfg "gopkg.in/gcfg.v1"
	"runtime"
	kc "common/kafkacluster/consumer"
)

var (
	Conf *Config
)

type Config struct {
	Base    struct {
			MaxProc   int      `gcfg:"maxproc"`
			PidFile   string   `gcfg:"pid"`
			PprofAddr []string `gcfg:"pprof"`
			LogPath   string   `gcfg:"log"`
			Debug     bool   `gcfg:"debug"`
		}

	Kafka   kc.Config

	Factory struct {
			MachineCount int //部署几台机器
			PartionCount int //kafka分区数量
		}

	PushUrl struct {
			Addr string
		}
}

func init() {
	Conf = &Config{}
	Conf.Base.MaxProc = runtime.NumCPU()
}

// Init init the configuration file.
func Init(confPath string) error {

	if err := gcfg.ReadFileInto(Conf, confPath); err != nil {
		return err
	}
	return nil
}

// Reload reload the configuration file.
func Reload(confPath string) error {
	tmp := &Config{}
	if err := gcfg.ReadFileInto(tmp, confPath); err != nil {
		return err
	}
	Conf = tmp
	return nil
}
